package edu.hawaii.its381b.client;

import com.google.gwt.safehtml.shared.SafeUri;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.event.dom.client.MouseDownHandler;
import com.google.gwt.event.dom.client.MouseDownEvent;
import com.google.gwt.event.dom.client.MouseOverHandler;
import com.google.gwt.event.dom.client.MouseOverEvent;
import com.google.gwt.event.dom.client.MouseOutHandler;
import com.google.gwt.event.dom.client.MouseOutEvent;
import com.google.gwt.event.dom.client.MouseUpHandler;
import com.google.gwt.event.dom.client.MouseUpEvent;

public class StartControl extends Composite{
	HorizontalPanel mainPanel;
	private Button btnStartButton= new Button("Start");
	private char the_s_Key = 115;
	private char the_S_Key = 83;
	private boolean gameNotStarted = true;
	
	public StartControl() {
		super();
		mainPanel = new HorizontalPanel();
		mainPanel.setStyleName("mainRootStyle");
		mainPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);		
		
		initWidget(mainPanel);
		mainPanel.setSize("600px", "200px");
		
		SafeUri WillyRURI = HermitCrabResources.INSTANCE.willyR().getSafeUri();
		Image imageWillyR = new Image(WillyRURI);
		mainPanel.add(imageWillyR);
		mainPanel.setCellHeight(imageWillyR, "195");
		mainPanel.setCellWidth(imageWillyR, "200");
		mainPanel.setCellVerticalAlignment(imageWillyR, HasVerticalAlignment.ALIGN_MIDDLE);
		mainPanel.setCellHorizontalAlignment(imageWillyR, HasHorizontalAlignment.ALIGN_CENTER);
		imageWillyR.setSize("195px", "195px");

		btnStartButton.addMouseDownHandler(new MouseDownHandler() {
			public void onMouseDown(MouseDownEvent event) {
				btnStartButton.setStyleName("StartStyleMouseDown");
			}
		});
		btnStartButton.addMouseUpHandler(new MouseUpHandler() {
			public void onMouseUp(MouseUpEvent event) {
				btnStartButton.setStyleName("StartStyle");
				updateGameStart();
			}
		});
		btnStartButton.addMouseOutHandler(new MouseOutHandler() {
			public void onMouseOut(MouseOutEvent event) {
				btnStartButton.setStyleName("StartStyle");
			}
		});
		btnStartButton.addMouseOverHandler(new MouseOverHandler() {
			public void onMouseOver(MouseOverEvent event) {
				btnStartButton.setStyleName("StartStyleMouseOver");
			}
		});

		mainPanel.add(btnStartButton);
		btnStartButton.setStyleName("StartStyle");
		mainPanel.setCellVerticalAlignment(btnStartButton, HasVerticalAlignment.ALIGN_MIDDLE);
		btnStartButton.setSize("128px", "75px");

		SafeUri flowerURI = HermitCrabResources.INSTANCE.flower().getSafeUri();
		Image imageFlower = new Image(flowerURI);
		mainPanel.add(imageFlower);
		mainPanel.setCellVerticalAlignment(imageFlower, HasVerticalAlignment.ALIGN_MIDDLE);
		imageFlower.setSize("122px", "97px");
	}
	
	public void updateGameStart(){
		gameNotStarted=false;
	}
	
	public boolean gameHasNotStarted(){
		return gameNotStarted;
	}
}